package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.Dish;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    // @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount) values(#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void add(ShoppingCart shoppingCart);


    // @Select("select id, name, image, user_id, dish_id, dish_flavor, number, amount from shopping_cart where user_id = #{userId} and dish_id = #{dishId} and dish_flavor = #{dishFlavor};")
    ShoppingCart selectByDishId(ShoppingCart shoppingCart);

    // @Update("update shopping_cart set amount = #{amount}, number = #{number} where user_id = #{userId} and dish_id =#{dishId} and dish_flavor = #{dishFlavor}")
    void update(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    @Select("select * from shopping_cart where user_id = #{userId} and dish_id =#{dishId} and dish_flavor = #{dishFlavor}")
    ShoppingCart selectByIdAndFlavor(ShoppingCartDTO shoppingCartDTO);

    // @Delete("delete from shopping_cart where user_id = #{userId} and dish_id =#{dishId} and dish_flavor = #{dishFlavor}")
    void deleteByIdAndFlavor(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> getByUserId(Long currentId);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clear(Long userId);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteAll(Long userId);
}
